home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-03-19 | 65.2 KB | 1,604 lines | [TEXT/MPS ] |
- #
- # ****************************************************************************
- #
- # File Name: Draw.Lib
- #
- # Contains: Tasks to help do testing of drawing operations
- #
- # Written by: KTA, KL, ML, GS et al
- #
- # Copyright: © 1993-1996 by Apple Computer, Inc., all rights reserved.
- #
- # ****************************************************************************
- # C h a n g e H i s t o r y (most recent first):
- # ****************************************************************************
- #
- # Vers Date Author Description
- # ---- -------- ------ ---------------------------------------------
- # 1.0.118> 5/1/96 MDF Modified so that the SetTool() task can be redirected
- # through the gSetTool global variable.
- # .0.117+> 5/1/96 MDF Modified so that the SetTool() task can be redirected through
- # the gSetTool global variable.
- # 1.0.117> 2/8/96 JC
- # 1.0.117+> 2/8/96 JC Changed all window .r (Rect) traits to .b (bound) traits and
- # changed any window insets to reflect new bound rect.
- # 1.0.116> 11/29/95 ML Draw - use RandomDrawObject to generate random object
- # .0.115+> 11/29/95 ML Draw - use RandomDrawObject to generate random object
- # 1.0.115> 11/27/95 ML Draw - update for gradients, background colors, text
- # colors, pet pats
- # .0.114+> 11/27/95 ML Draw - update for gradients, background colors, text colors, pet
- # pats
- # 1.0.114> 11/10/95 ML InitDraw() - Added support for gradients, background colors,
- # text colors, and pen patterns. CheckObjectStruct() - Object
- # struct now has 9 elements. SetAttributes() - removed elemNum -
- # not used, now call SetObjectAttribute for each attribute.
- # SetObjectAttribute() - created. Object Structure Accessors() -
- # Added support for gradients, background colors, and pen
- # patterns. Draw() - allow pThePointList to be user defineable.
- # SetColor(), SetLine(), SetPattern() - Call SetPaletteItem.
- # SetBackgroundColor(), SetTextColor(), SetPenPattern(),
- # SetGradient(), SetPaletteItem(), RandomDrawObject() - created.
- # Whew!
- # .0.113+> 11/7/95 ML Draw() - allow pThePointList to be user defineable.
- # 1.0.113> 12/12/94 ML Removed gTargetCheck
- # .0.112+> 12/12/94 ML Removed gTargetCheck
- # 1.0.112> 12/1/94 ML Added Error Handling Support
- # .0.111+> 12/1/94 ML Added Error Handling Support
- # 1.0.111> 7/18/94 KTA CheckSetup() - changed the reporting so the current palette is 4
- # elements it is global coordinates and if 5 it is relative to the
- # specified window.
- # 1.0.110> 5/9/94 KTA DrawObject() - Added gDrawObjectHook.
- # <1.0.19> 5/2/94 KTA Removed all references to kPullOffPal, kScrollPal.
- # <1.0.18> 4/28/94 KTA DrawObject() - Add TCS for drawing the object
- # <1.0.17> 4/18/94 KTA UseTool routines - Added Quotes to the pointlists (really).
- # <1.0.16> 4/18/94 KTA UseTool routines - Added Quotes to the pointlists.
- # <1.0.15> 4/15/94 ML add kDragOff to globals declaration in DrawObject()!
- # <1.0.14> 3/17/94 KTA Added support for kMenuItemPopUpPal palettes.
- # <1.0.13> 3/16/94 KTA Added kDragOff tool.
- # <1.0.12> 3/16/94 KTA New TCS set - kTCSetUseTool.
- # <1.0.11> 3/16/94 KTA Added TCS calls to UseTool routines.
- # <1.0.10> 12/2/93 KTA CheckObjectStruct() doesn't choke on kMultiClickDrag tools
- # anymore.
- # <1.0.9> 11/19/93 NAGA Modify TCS format
- # <1.0.8> 8/30/93 KTA Updated task headers and parameters.
- # <1.0.7> 8/25/93 KTA Added support for parity checking the TCS stack.
- # <1.0.6> 8/3/93 KTA DrawObject()- Fixed bug where directCoord Tools weren't setting
- # any attributes.
- # <1.0.4> 6/8/93 NAGA unmark tasks that are not published
- # <2+> 6/8/93 NAGA unmark tasks that are not published
- # <1+> 5/21/93 NAGA Adding header and porting old files to follow new standards
- #
- # ****************************************************************************
- #
-
- ########################################################################
- # External libraries
- #=======================================================================
- Libraries "Palette.Lib", "String.Lib","OutPut.lib", "TCS.Lib", "Geometry.Lib",
- "UserInterface.Lib", "ExceptionHandling.Lib";
-
- #########################################################################
- # InitDraw()
- #========================================================================
- # Author: KTA
- # Description: Initializes the Draw globals.
- # Parameters: None
- # Returns: Nada
- # Examples: InitDraw();
- # Assumptions:
- #========================================================================
- # History:
- # ML 11/10/95 Added support for gradients, background colors, text colors,
- # and pen patterns
- # JC 2/8/96 Changed "global gWindowInset := {0,20,20,20};" to "{0,0,20,20}".
- # MDF 04/29/96 Added task reference for SetTool.
- #########################################################################
- TASK InitDraw()
- begin
- ############## Task References ############
- global gSetTool := Task SetTool; # Requires VU 2.0
- global gSetLine := Task SetLine; # Requires VU 2.0
- global gSetColor := Task SetColor; # Requires VU 2.0
- global gSetPattern := Task SetPattern; # Requires VU 2.0
- global gSetGradient := Task SetGradient; # Requires VU 2.0
- global gSetBackgroundColor := Task SetBackgroundColor; # Requires VU 2.0
- global gSetTextColor := Task SetTextColor; # Requires VU 2.0
- global gSetPenPattern := Task SetPenPattern; # Requires VU 2.0
-
- ############## Tool Type Defines ############
- global kClick := 1;
- global kDrag := 2;
- global kDragClick := 3;
- global kMultiDrag := 4;
- global kMultiClick := 5;
- global kMultiClickDrag := 6;
- global kDragOff := 7;
-
- ############## Palette Type Defines ########
- global kPalDocWind := 1;
- global kPalWind := 2;
- global kPopUpPal := 3;
- global kMenuItemPopUpPal := 4;
-
- ############## Script Contants ############
- global gWindowInset := {0,0,20,20}; # Inset to wind to get content region
- global gScreenInset := {0,20,0,0}; # Inset to screen
- global gBoundingRect := {}; #
- global gVoidRect := {}; # Rect not to draw in - coordinates should be RelativeToWindow
- global gLineWeights := {}; # Line Weights
- global gNumPoints := 6; # Number of points for all multipoint tools
- global gDrawObject := 0; # Object Number in a given suite (incremented by DrawObject)
- end;
-
- #########################################################################
- # CheckObjectStruct(pObjectStruct)
- #========================================================================
- # Author: KTA
- # Description: Check validity of elements in pObjectStruct.
- # Parameters: pObjectStruct - the objectStruct to check
- # Returns: 0 - objectStruct is hosed
- # 1 - objectStruct is OK
- # Example: returnVal := CheckObjectStruct(pObjectStruct);
- #========================================================================
- # History:
- # KTA 12/01/93 kMultiClickDrag tools weren't supported added
- # elemType <= 6 (bug #1117685)
- # KTA 3/16/94 Added KDragOff tools which requires support of elemType = 7
- # ML 11/10/95 Object struct now has 9 elements
- #########################################################################
- TASK CheckObjectStruct(pObjectStruct)
- begin
- if (global gDebugFlag)
- println "----- CheckObjectStruct() - Draw.lib --------";
- global gNumPoints;
- returnVal := 1;
-
- if not(Card(pObjectStruct) = 9)
- begin
- Println "!@#$% CheckObjectFailure - Card(pObjectStruct) - ", Card(pObjectStruct);
- returnVal := 0;
- end;
-
- ## Tool Struct
- elemStruct := GetElemStruct(pObjectStruct);
- if not(Card(elemStruct) = 6)
- begin
- Println "!@#$% CheckObjectFailure - Card(elemStruct) - ", Card(elemStruct);
- returnVal := 0;
- end;
-
- ## ToolType
- elemType := GetElemType(elemStruct);
- if not (elemStruct = 'Random')
- begin
- if not((elemType >= 0) and (elemType <= 7) )
- begin
- Println "!@#$% CheckObjectFailure - elemType - ", ElemType;
- returnVal := 0;
- end;
- end;
-
- ## Tool Name
- elemName := GetElemName(elemStruct);
- if not (elemStruct = 'Random')
- begin
- if not( TypeOf(elemName) = "string" )
- begin
- Println "!@#$% CheckObjectFailure - elemName - ", elemName;
- returnVal := 0;
- end;
- end;
-
- ## DoubleClick
- elemDblClk := GetElemDblClk(elemStruct);
- if not (elemStruct = 'Random')
- begin
- if not((elemDblClk = 0) or (elemDblClk = 1) )
- begin
- Println "!@#$% CheckObjectFailure - elemDblClk - ", elemDblClk;
- returnVal := 0;
- end;
- end;
-
- ## Pointlist
- pointList := GetPointList(pObjectStruct);
- if (global gDebugFlag)
- println "This is the pointlist",pointList;
- (*
- if not((Card(pointList) = gNumPoints) or (Card(pointList) = elemType))
- begin
- Println "!@#$% CheckObjectFailure - pointList - ", pointList;
- returnVal := 0;
- end;
-
- ## Line
- theLine := GetLine(pObjectStruct);
- if not((TypeOF(theLine) = "list") and (Card(theLine) = 3) or (theLine = 0))
- begin
- Println "!@#$% CheckObjectFailure - theLine - ", theLine;
- returnVal := 0;
- end;
-
- ## Color
- theCol := GetColor(pObjectStruct);
- if not((TypeOF(theCol) = "list") and (Card(theCol) = 3) or (theCol = 0))
- begin
- Println "!@#$% CheckObjectFailure - theCol - ", theCol;
- returnVal := 0;
- end;
-
- ## Pattern
- thePat := GetPattern(pObjectStruct);
- if not((TypeOF(thePat) = "list") and (Card(thePat) = 3) or (thePat = 0))
- begin
- Println "!@#$% CheckObjectFailure - thePat - ", thePat;
- returnVal := 0;
- end;
- *)
- if (global gDebugFlag) # Set gDebugFlag to TRUE to output variables for debugging
- begin
- Println "======= DebugStr - CheckObject() in Draw.Lib ======";
- Println " pObjectStruct - ", {pObjectStruct};
- Println " elemStruct - ", {elemStruct};
- Println " elemType - ", {elemType};
- Println " elemName - ", {elemName};
- Println " elemDblClk - ", {elemDblClk};
- Println " pointList - ", {pointList};
- end;
-
- return returnVal;
- end; # CheckObjectStruct()
-
- #########################################################################
- # DrawObject(pObjectStruct, pSpecifier)
- #========================================================================
- # Author: DMM / KTA
- # Description: Main routine in the Draw Libraries. Calls all subroutines
- # necessary to draw a given object, passing the appropriate
- # elements from the pObjectStruct input param.
- # Parameters: pObjectStruct := {
- # {ToolStruct},
- # {PointList},
- # {PatternStruct},
- # {LineStruct},
- # {ColorStruct}
- # };
- # pSpecifier - Specifies the window (or Rect) to draw in)
- # Returns: 1 - exercises went OK
- # 0 - error in drawing object
- # Examples: noError := DrawObject(objectStruct,specifier);
- # DrawObject({global SelectTool, {{25,15}}, {12,2 ,’Pattern’}, 0, ‘Random’});
- #========================================================================
- # History:
- # KTA 8/3/92 Fixed bug where directCoord Tools weren't setting any attributes
- # ml 4/14/94 Add global kDragOff to globals declaration
- # KTA 4/28/94 Added TCS for drawing the object
- # KTA 5/9/94 Added gDrawObjectHook
- # ML 12/12/94 Removed gTargetcheck
- # MDF 04/29/96 Changed calls to SetTool into calls to gSetTool.
- #########################################################################
- TASK DrawObject(pObjectStruct := {}, pSpecifier := 0) begin
- global kClick, kDrag, kDragOff, kDragClick, kMultiDrag, kMultiClickDrag,
- kMultiClick,gToolsThatUseLineWeight, gDrawObject;
- gDrawObject := gDrawObject + 1; # Increment the object number for TCS info
- TempMouse := MouseSpeed(5);
- failStr := '';
-
- if (global gDebugFlag)
- println "----- DrawObject() - Draw.lib --------";
-
- ## Call accessors to access object struct
- ToolStruct := GetElemStruct(pObjectStruct);
- if (ToolStruct = 'Random')
- begin
- pObjectStruct := InsertElemStruct(call(global gSetTool,ToolStruct,0),pObjectStruct); # insert a random one but don't select it.
- ToolStruct := GetElemStruct(pObjectStruct);
- if (global gDebugFlag)
- println "----- This is the ObjectStruct after inserting Toolstruct -", pObjectStruct;
- end;
- elemPalNum := GetPalNum(ToolStruct);
- elemType := GetElemType(ToolStruct);
- elemName := GetElemName(ToolStruct);
- elemDblClk := GetElemDblClk(ToolStruct);
- elemNum := GetElemNum(ToolStruct);
- SetAttributeFlag := GetSetAttribute(ToolStruct);
-
- pointList := SetPointList(pObjectStruct, pSpecifier);
- pObjectStruct := InsertPointList(pointList, pObjectStruct);
-
- returnVal := CheckObjectStruct(pObjectStruct); #
- if (returnVal)
- begin
- if (TypeOf(elemPalNum) = 'list') ## Handle Coordinate tools
- returnVal := PalettePicker(ToolStruct);
- else
- call(global gSetTool,ToolStruct,,gDrawObject);
- ###########################################################
- #### Call to set object attributes and update pObjectStruct
- ###########################################################
- if(not(SetAttributeFlag) or ((Typeof(SetAttributeFlag) = 'string') and (Card(GetAttributes(ToolStruct)) = 1)))
- begin
- pObjectStruct := InsertPattern(0, pObjectStruct); # Insert NIL patternStruct
- pObjectStruct := InsertColor(0, pObjectStruct); # Insert NIL ColorStruct
- pObjectStruct := InsertLine(0, pObjectStruct); # Insert NIL LineStruct
- end;
- else if(SetAttributeFlag = 1)
- pObjectStruct := SetAttributes(pObjectStruct,gDrawObject);
-
- if(elemType) # Tool Type is zero because we don't want to draw an object
- begin
- # inform the user of the object we are going to draw
- pointStr := PointListToStr(pointList); # put pointList into a string
- str := "-- Drawing object defined by points {pointStr}";
- if (elemType = kClick)
- LogStr(Str);
- else
- begin
- # inform user of actions to take place before/during/after each move
- if ((elemType = kDrag) or (elemType = kMultiDrag))
- LogStr("{str} Will hold mouse down during move");
- else if (elemType = kMultiClickDrag)
- LogStr("{str} Will hold mouse down during each move and release at each destination point");
- else if (elemType = kMultiClick)
- LogStr("{str} Will click at each point");
- end;
-
- temp := global gDisableAllLogging;
- if not(global gDebugFlag)
- gDisableAllLogging := 1;
-
- # Call the UseTool Routines
- if (elemType = kClick)
- returnVal := UseClickTool(pointList,pSpecifier);
- else if (elemType = kDrag)
- returnVal := UseDragTool( pointList, pSpecifier, ,elemDblClk );
- else if (elemType = kDragClick)
- returnVal := UseDragClickTool( pointList, pSpecifier, ,elemDblClk );
- else if (elemType = kMultiDrag)
- returnVal := UseMultiDragTool( pointList, pSpecifier, elemDblClk );
- else if (elemType = kMultiClick)
- returnVal := UseMultiClickTool( pointList, pSpecifier, elemDblClk );
- else if (elemType = kMultiClickDrag)
- returnVal := UseMultiClickDragTool( pointList, pSpecifier, elemDblClk );
- else if (elemType = kDragOff)
- returnVal := UseDragOffTool( pointList, pSpecifier, ,elemDblClk );
- else begin
- LogStr("No tool function declared for tool type {elemType}");
- returnVal := 0;
- end;
- gDisableAllLogging := temp;
- end;
- else
- Println "Tool Type for this tool is 0, so no object drawn.";
-
- TCSStart({ 2, global kTCSetDraw },"Draw Object"); # Start TCS
-
- isDialog := DialogCheck('',1,,[window o:1 s:Dialog]!);
- if (isDialog) # Check for any dialogs
- begin
- returnVal := 0;
- TCReturnVal := 0;
- failStr := "!@#$% Failed to draw object" + ' / ' + isDialog;
- LogStr(failStr);
- end;
- else if (returnVal)
- begin
- if(SetAttributeFlag = 2) or (Typeof(SetAttributeFlag) = 'string')
- pObjectStruct := SetAttributes(pObjectStruct,gDrawObject);
- ### To handle text entry
- if(Typeof(SetAttributeFlag) = 'string')
- TypeStr(SetAttributeFlag);
-
- isDialog := DialogCheck('',1,,[window o:1 s:Dialog]!);
- if (isDialog) # Check for any dialogs
- begin
- returnVal := 0;
- TCReturnVal := 0;
- failStr := "!@#$% Failed to draw object" + ' / ' + isDialog;
- LogStr(failStr);
- end;
- else
- begin
- LogStr("----- Finished drawing object -----");
- returnVal := pObjectStruct;
- TCReturnVal := 1;
- end;
- end;
-
- TCSEnd({ 2, global kTCSetDraw },TCReturnVal,failStr,,"'{pObjectStruct}'");
- end;
-
- if(global gDrawObjectHook)
- call(gDrawObjectHook);
-
- Println "¶ theObject - ", returnVal;
- println "-----------------------------------";
- println ;
- MouseSpeed(TempMouse);
- return(returnVal);
- end; # DrawObject()
-
- #########################################################################
- # SetAttributes(pObjectStruct,pDrawObject)
- #========================================================================
- # Author: KTA
- # Description: This task takes a complete objectStruct as a parameter, it will
- # determine if the tool being used to draw with can set various
- # attributes (patterns, lines, and colors). If so the appropriate
- # tasks will be called and the actual attribute structs used will
- # be inserted into the objectStruct prior to returning.
- # Parameters: pObjectStruct - a complete objectStruct - note some elements will
- # evaluate to 0 or random upon entry - the random
- # elements will be replaced with actual atribute
- # struct prior to exiting. Elements that are 0 will
- # not be set.
- # pDrawObject - This is the number that is used to tie together
- # all elements that make up an object for TCS
- # logging purposes.
- # Returns: pObjectStruct - Setting attributes went OK
- # 0 - error in - Setting attributes
- # Examples:
- #========================================================================
- # History:
- # ML 11/09/95 removed elemNum - not used.
- # ML 11/09/95 now call SetObjectAttribute for each attribute
- #########################################################################
- TASK SetAttributes(pObjectStruct, pDrawObject)
- begin
- global gSetPattern, gSetLine, gSetColor, gSetGradient, gSetBackgroundColor,
- gSetTextColor, gSetPenPattern;
-
- elemStruct := GetElemStruct(pObjectStruct);
-
- ###########################################################
- #### Call to set object attributes and update pObjectStruct
- ###########################################################
-
- ##### SetPattern ######
- pObjectStruct := SetObjectAttribute(pObjectStruct, elemStruct, pDrawObject,
- task GetPatternFlag, task GetPattern,
- gSetPattern, task InsertPattern, "pattern");
- ##### SetLine ######
- pObjectStruct := SetObjectAttribute(pObjectStruct, elemStruct, pDrawObject,
- task GetLineFlag, task GetLine,
- gSetLine, task InsertLine, "Line");
-
- ##### SetColor ######
- pObjectStruct := SetObjectAttribute(pObjectStruct, elemStruct, pDrawObject,
- task GetColorFlag, task GetColor,
- gSetColor, task InsertColor, "Color");
-
- ##### SetGradient ######
- pObjectStruct := SetObjectAttribute(pObjectStruct, elemStruct, pDrawObject,
- task GetGradientFlag, task GetGradient,
- gSetGradient, task InsertGradient, "Gradient");
-
- ##### SetBackgroundColor ######
- pObjectStruct := SetObjectAttribute(pObjectStruct, elemStruct, pDrawObject,
- task GetBackgroundColorFlag, task GetBackgroundColor,
- gSetBackgroundColor, task InsertBackgroundColor,
- "Background Color");
-
- ##### gSetTextColor ######
- pObjectStruct := SetObjectAttribute(pObjectStruct, elemStruct, pDrawObject,
- task GetTextColorFlag, task GetTextColor,
- gSetTextColor, task InsertTextColor,
- "Text Color");
-
- ##### gSetPenPattern ######
- pObjectStruct := SetObjectAttribute(pObjectStruct, elemStruct, pDrawObject,
- task GetPenPatternFlag, task GetPenPattern,
- gSetPenPattern, task InsertPenPattern,
- "Pen Pattern");
-
- return(pObjectStruct);
- end; # SetAttributes()
-
- #########################################################################
- # SetObjectAttribute(pObjectStruct,pDrawObject)
- #========================================================================
- # Author: ML
- # Description: Sets an objects attribute and returns the updated object structure.
- # Parameters: pObjectStruct - a complete objectStruct - note some elements will
- # evaluate to 0 or random upon entry - the random
- # elements will be replaced with actual atribute
- # struct prior to exiting. Elements that are 0 will
- # not be set.
- # pDrawObject - This is the number that is used to tie together
- # all elements that make up an object for TCS
- # logging purposes.
- # Returns: pObjectStruct - Setting attributes went OK
- # 0 - error in - Setting attributes
- # Examples:
- #========================================================================
- # History:
- #########################################################################
- task SetObjectAttribute(pObjectStruct, pElemStruct, pDrawObject, pFlagTask,
- pGetAttributeTask, pSetAttributeTask, pInsertAttributeTask,
- pAttributeName)
- begin
- if(call(pFlagTask, pElemStruct))
- begin
- theAttribute := call(pGetAttributeTask, pObjectStruct);
- if (theAttribute)
- begin
- theAttributeStruct := Call(pSetAttributeTask, theAttribute,,pDrawObject);
- pObjectStruct := call(pInsertAttributeTask, theAttributeStruct, pObjectStruct);
- end;
- if (global gDebugFlag)
- println "This is the pObjectStruct after SetObjectAttribute {pAttributeName} - ", pObjectStruct;
- end;
- else
- begin
- if (global gDebugFlag)
- LogStr("This is not a {pAttributeName} tool");
- pObjectStruct := call(pInsertAttributeTask, 0, pObjectStruct);
- end;
- return (pObjectStruct);
- end;
-
- #########################################################################
- # UseClickTool()
- #========================================================================
- # Author: DMM
- # Description: Move to point and click once.
- # Parameters: pPointList - List containing a point.
- # pSpecifier - Window specifier for the window to move relative to.
- # Returns: 1 - Clicked
- # Examples: UseClickTool();
- # Assumptions: None
- #========================================================================
- # History:
- # KTA 4/18/94 Added Quotes to the pointlist
- #########################################################################
- TASK UseClickTool(pPointList, pSpecifier)
- begin
- global gDrawObject;
- if (global gDebugFlag)
- println "----- UseClickTool() - Draw.lib --------";
-
- TCSStart({ 1, global kTCSetUseTool },"Use Click tool"); # Start TCS
-
- thePt := pPointList[1]; # get first point
- returnVal := MoveRelativeToWindow(thePt[1],thePt[2],pSpecifier, 2); # move to the first point
-
- if(returnVal) # MoveRelativeToWindow returns global coordinates and we want a success/Failure flag
- returnVal := 1;
-
- thePointList := "'{pPointList}'";
- TCSEnd({ 1, global kTCSetUseTool }, returnVal,,gDrawObject,thePointList);
-
- return(returnVal);
- end;
-
- #########################################################################
- # UseDragTool(pPointList, pSpecifier, pMouseDown, pDClickToEnd)
- #========================================================================
- # Author: DMM
- # Description: Drag from the current location.
- # Parameters: pPointList - Point to move to.
- # pSpecifier - Window specifier in which to drag in.
- # pMouseDown - 0 - don't hold mouse key down while moving
- # 1 - press mouse key down - move - release
- # 2 - Click after moving - no mouse down during move
- # 3 - press mouse key down - move - don't release
- # 4 - move - release
- # pDClickToEnd - Boolean flag indicating whether or not to double
- # click the mouse after dragging.
- # Returns: returnVal - what moveRelativeToWindow returns.
- # Examples: UseDragTool({{100,200},{200,200}}, 0, 1,0);
- # Assumptions: All points are specified relative to window.
- #========================================================================
- # History:
- # KTA 4/18/94 Added Quotes to the pointlist
- # ML 12/1/94 Added Error Handling Support
- #########################################################################
- TASK UseDragTool(pPointList:= {}, pSpecifier := 0, pMouseDown := 6, pDClickToEnd := 0)
- begin
- global gDrawObject;
- returnVal := 0;
- if (global gDebugFlag)
- println "----- UseDragTool() - Draw.lib --------";
- TCSStart({ 2, global kTCSetUseTool },"Use Drag tool"); # Start TCS
-
- returnVal := MoveRelativeToWindow( pPointList ,, pSpecifier,pMouseDown);
- if (pDClickToEnd) begin # doubleClick to end sequence
- _doubleClick();
- #LogStr("Double-clicked the mouse button to end drawing sequence");
- end;
-
- if(returnVal) # MoveRelativeToWindow returns global coordinates and we want a success/Failure flag
- returnVal := 1;
-
- thePointList := "'{pPointList}'";
- TCSEnd({ 2, global kTCSetUseTool }, returnVal,,gDrawObject,thePointList);
-
- return(returnVal);
- end;
-
- #########################################################################
- # UseDragClickTool(pPointList, pSpecifier, pMouseDown, pDClickToEnd)
- #========================================================================
- # Author: KTA
- # Description: Drag from the current location. Then click at a different point.
- # Parameters: pPointList - List of points to move to.
- # pSpecifier - Window specifier in which to drag in.
- # pMouseDown - 0 - don't hold mouse key down while moving
- # 1 - press mouse key down - move - release
- # 2 - Click after moving - no mouse down during move
- # 3 - press mouse key down - move - don't release
- # 4 - move - release
- # pDClickToEnd - Boolean flag indicating whether or not to double
- # click the mouse after dragging.
- # Returns: returnVal - what MoveRelativeToWindow returns.
- # Examples: UseDragClickTool({{100,200},{100,200}, {200,300}},0,1,0);
- # Assumptions: All points are specified relative to window.
- #========================================================================
- # History:
- # KTA 4/18/94 Added Quotes to the pointlist
- # ML 12/1/94 Added Error Handling Support
- #########################################################################
- TASK UseDragClickTool(pPointList:= {}, pSpecifier := 0, pMouseDown := 1, pDClickToEnd := 0)
- begin
- global gDrawObject;
- if (global gDebugFlag)
- begin
- println "----- UseDragClickTool() - Draw.lib --------";
- println "pPointList - ", pPointList;
- end;
- OriginalPointlist := pPointList;
- TCSStart({ 5, global kTCSetUseTool },"Use Drag-Click tool"); # Start TCS
-
- thePt := pPointList[1]; # get first point
- MoveRelativeToWindow(thePt[1],thePt[2],pSpecifier); # move to the first point and set relativeFlag
- pPointList := remove(1,pPointList); # remove first point from list - we already used it
-
- returnVal := 0;
- dragPt := pPointList[1];
- clickPt := pPointList[2];
-
- dragH := dragPt[1];
- dragV := dragPt[2];
- clickH := clickPt[1];
- clickV := clickPt[2];
-
- returnVal := MoveRelativeToWindow( dragH , dragV , pSpecifier, pMouseDown);
- returnVal := MoveRelativeToWindow( clickH ,clickV , pSpecifier, 2);
-
- if (pDClickToEnd)
- _doubleClick();
-
- if(returnVal) # MoveRelativeToWindow returns global coordinates and we want a success/Failure flag
- returnVal := 1;
-
-
- thePointList := "'{OriginalPointlist}'";
- TCSEnd({ 5, global kTCSetUseTool }, returnVal,,gDrawObject,thePointList);
-
- return(returnVal);
- end; # UseDragClickTool()
-
- #########################################################################
- # UseMultiDragTool(pPointList, pSpecifier, pDClickToEnd)
- #========================================================================
- # Author: DMM
- # Description: mouseDown-drag-drag-drag-drag-release.
- # Parameters: pPointList - List of points to move to.
- # pSpecifier - Window specifier in which to drag in.
- # pDClickToEnd - Boolean flag indicating whether or not to double
- # click the mouse after dragging.
- # Returns: returnVal - what MoveRelativeToWindow returns.
- # Examples: UseMultiDragTool({{100,200}, {200,300}},0,0);
- # Assumptions: All points are specified relative to window.
- #========================================================================
- # History:
- # KTA 4/18/94 Added Quotes to the pointlist
- # ML 12/1/94 Added Error Handling Support
- #########################################################################
- TASK UseMultiDragTool(pPointList := {}, pSpecifier := 0, pDClickToEnd := 0)
- begin
- global gDrawObject;
- if (global gDebugFlag)
- println "----- UseMultiDragTool() - Draw.lib --------";
-
- TCSStart({ 3, global kTCSetUseTool },"Use MultiDrag tool"); # Start TCS
- returnVal := MoveRelativeToWindow( pPointList ,, pSpecifier,6);
-
- if (pDClickToEnd)
- _doubleClick();
-
- if(returnVal) # MoveRelativeToWindow returns global coordinates and we want a success/Failure flag
- returnVal := 1;
-
- thePointList := "'{pPointList}'";
- TCSEnd({ 3, global kTCSetUseTool }, returnVal,,gDrawObject,thePointList);
-
- return(returnVal);
- end;
-
- #########################################################################
- # UseMultiClickTool(pPointList, pSpecifier, pDClickToEnd)
- #========================================================================
- # Author: DMM
- # Description: click-move-click-move….
- # Parameters: pPointList - List of points to move to.
- # pSpecifier - Window specifier in which to drag in.
- # pDClickToEnd - Boolean flag indicating whether or not to double
- # click the mouse after dragging.
- # Returns: returnVal - what MoveRelativeToWindow returns.
- # Examples: UseMultiClickTool({{100,200}, {200,300}},0,0);
- # Assumptions: All points are specified relative to window.
- #========================================================================
- # History:
- # KTA 4/18/94 Added Quotes to the pointlist
- # ML 12/1/94 Added Error Handling Support
- #########################################################################
- TASK UseMultiClickTool(pPointList, pSpecifier := 0, pDClickToEnd := 0)
- begin
- global gDrawObject;
- if (global gDebugFlag)
- println "----- UseMultiClickTool() - Draw.lib --------";
-
- TCSStart({ 4, global kTCSetUseTool },"Use MultiClick tool"); # Start TCS
-
- returnVal := MoveRelativeToWindow( pPointList ,, pSpecifier, 5);
-
- if (pDClickToEnd)
- _doubleClick();
-
- if(returnVal) # MoveRelativeToWindow returns global coordinates and we want a success/Failure flag
- returnVal := 1;
-
-
- thePointList := "'{pPointList}'";
- TCSEnd({ 4, global kTCSetUseTool }, returnVal,,gDrawObject,thePointList);
-
- return(returnVal);
- end;
-
- #########################################################################
- # UseMultiClickDragTool(pPointList, pSpecifier, pDClickToEnd)
- #========================================================================
- # Author: KTA
- # Description: mouseDown-drag-mouseUp-mouseDown-drag-mouseUp….
- # Parameters: pPointList - List of points to move to.
- # pSpecifier - Window specifier in which to drag in.
- # pDClickToEnd - Boolean flag indicating whether or not to double
- # click the mouse after dragging.
- # Returns: Nothing
- # Examples: UseMultiClickDragTool();
- # Assumptions: All points are
- # specified relative to window.
- #========================================================================
- # History:
- # KTA 4/18/94 Added Quotes to the pointlist
- # ML 12/1/94 Added Error Handling Support
- #########################################################################
- TASK UseMultiClickDragTool(pPointList, pSpecifier := 0, pDClickToEnd := 0)
- begin
- global gDrawObject;
- if (global gDebugFlag)
- println "----- UseMultiClickDragTool() - Draw.lib --------";
- oldMouseSpeed := mouseSpeed(4); # slow down mouse
- mouseDown := 4;
-
- TCSStart({ 6, global kTCSetUseTool },"Use MultiClickDrag tool"); # Start TCS
-
- OriginalPointlist := pPointList;
- thePt := pPointList[1]; # get first point
- MoveRelativeToWindow(thePt[1],thePt[2],pSpecifier); # move to the first point and set relativeFlag
- pPointList := remove(1,pPointList); # remove first point from list - we already used it
-
- for each PairPts in pPointList
- begin
- xCoord := PairPts[1];
- yCoord := PairPts[2];
- returnVal := MoveRelativeToWindow( xCoord ,yCoord, pSpecifier,1);
- end;
-
-
- mouseSpeed(oldMouseSpeed); # restore mouse speed
- if (pDClickToEnd)
- _doubleClick();
-
- if(returnVal) # MoveRelativeToWindow returns global coordinates and we want a success/Failure flag
- returnVal := 1;
-
- thePointList := "'{OriginalPointlist}'";
- TCSEnd({ 6, global kTCSetUseTool }, returnVal,,gDrawObject,thePointList);
- Return(returnVal);
- end;
-
- #########################################################################
- # UseDragOffTool(pPointList, pSpecifier, pMouseDown, pDClickToEnd)
- #========================================================================
- # Author: KTA
- # Description: Drag Tool into the content region of the window.
- # Parameters: pPointList - Point to move to.
- # pSpecifier - Window specifier in which to drag in.
- # pMouseDown - 0 - don't hold mouse key down while moving
- # 1 - press mouse key down - move - release
- # 2 - Click after moving - no mouse down during move
- # 3 - press mouse key down - move - don't release
- # 4 - move - release
- # pDClickToEnd - Boolean flag indicating whether or not to double
- # click the mouse after dragging.
- # Returns: returnVal - what moveRelativeToWindow returns.
- # Examples: UseDragOffTool({{100,200}}, 0, 1,0);
- # Assumptions: All points are specified relative to window.
- #========================================================================
- # History:
- # KTA 4/18/94 Added Quotes to the pointlist
- # ML 12/1/94 Added Error Handling Support
- #########################################################################
- TASK UseDragOffTool(pPointList:= {}, pSpecifier := 0, pMouseDown := 1, pDClickToEnd := 0)
- begin
- global gDrawObject;
- returnVal := 0;
- if (global gDebugFlag)
- println "----- UseDragOffTool() - Draw.lib --------";
- TCSStart({ 7, global kTCSetUseTool },"Use DragOff tool"); # Start TCS
-
- returnVal := MoveRelativeToWindow( pPointList ,, pSpecifier,pMouseDown);
- if (pDClickToEnd) begin # doubleClick to end sequence
- _doubleClick();
- #LogStr("Double-clicked the mouse button to end drawing sequence");
- end;
-
- if(returnVal) # MoveRelativeToWindow returns global coordinates and we want a success/Failure flag
- returnVal := 1;
-
- thePointList := "'{pPointList}'";
- TCSEnd({ 7, global kTCSetUseTool }, returnVal,,gDrawObject,thePointList);
-
- return(returnVal);
- end; # UseDragOffTool()
-
- #########################################################################
- # Object Structure Accessors()
- #========================================================================
- # Author: DMM
- # Description: These functions access the data in an objectStruct data
- # structure.
- # Parameters: objectStruct
- # Returns: the requested data element or list
- #========================================================================
- # History:
- # ML 11/10/95 Added support for gradients, background colors, text colors,
- # and pen patterns
- #########################################################################
- ## objectStruct is the data structure that completely specifies the object to be drawn
- ## objectStruct {
- ## ElemStruct
- ## PointList
- ## Pattern
- ## Line
- ## Color
- ## }
-
- task GetElemStruct(objectStruct) begin return( objectStruct[1] ); end;
- task GetPointList(objectStruct) begin return( objectStruct[2] ); end;
- task GetPattern(objectStruct) begin return( objectStruct[3] ); end;
- task GetLine(objectStruct) begin return( objectStruct[4] ); end;
- task GetColor(objectStruct) begin return( objectStruct[5] ); end;
- task GetGradient(objectStruct) begin return( objectStruct[6] ); end;
- task GetBackgroundColor(objectStruct) begin return( objectStruct[7] ); end;
- task GetTextColor(objectStruct) begin return( objectStruct[8] ); end;
- task GetPenPattern(objectStruct) begin return( objectStruct[9] ); end;
-
- task InsertElemStruct(tS, oS) begin return( replace( tS, 1, oS )); end;
- task InsertPointList(pts, oS) begin return( replace( pts, 2, oS )); end;
- task InsertPattern(pat, oS) begin return( replace( pat, 3, oS )); end;
- task InsertLine(lin, oS) begin return( replace( lin, 4, oS )); end;
- task InsertColor(col, oS) begin return( replace( col, 5, oS )); end;
- task InsertGradient(col, oS) begin return( replace( col, 6, oS )); end;
- task InsertBackgroundColor(col, oS) begin return( replace( col, 7, oS )); end;
- task InsertTextColor(col, oS) begin return( replace( col, 8, oS )); end;
- task InsertPenPattern(col, oS) begin return( replace( col, 9, oS )); end;
-
-
- #########################################################################
- # MakePointList( pInset, pSpecifier, pNumPoints, pClosed, pVoidRect )
- #========================================================================
- # Author: DMM
- # Description: Generates a list of random points
- # Parameters: pInset - inset into window for ppoints to be generated.
- # pSpecifier - Window specifier for the window to generate points in.
- # pNumPoints - number of points to comprise the object
- # pClosed - 1 for closed object (first-last point the same)
- # 0 for open object (first-last point different)
- # pVoidRect - no points in object should be in this rectangle
- # Returns: List of Points.
- # Examples: theObject := MakePointList(rect); # 4 point closed object
- # theObject := MakePointList(theWindow.r, 4,1,thePalette.r);
- #========================================================================
- # History:
- #
- # JC 2/8/96 Changed "pInset :={ 0,20,20,20 }" to "{0,0,20,20}".
- ########################################################################
- TASK MakePointList(pInset :={ 0,0,20,20 } , pSpecifier := 0, pNumPoints := global gNumPoints, pClosed := 0, pVoidRect := {} )
- begin
- if (global gDebugFlag)
- println "----- MakePointList() - Draw.lib --------";
- global gWindowInset, gVoidRect,gNumPoints, gBoundingRect;
- # To help assure drawing occurs in the content region
- if (gBoundingRect) # Window Rect
- boundingRect := gBoundingRect;
- else
- boundingRect := pSpecifier;
-
- if (gWindowInset) # Window inset
- pInset := gWindowInset;
- if (gVoidRect) # No points will be in this rect -
- pVoidRect := gVoidRect; # Coordinates should be relative to window
- pointList := GetRandomPointsRelativeToWindow(pInset, boundingRect,pNumPoints);
- if (pNumPoints = 1) # When only one set of point is required
- pointlist := { pointlist };
-
- # Last point is same as first
- if(pClosed)
- pointList := replace(pointList[1], pNumPoints, pointList );
-
- # only points that are not in the void rectangle
- if (pVoidRect)
- begin
- for x := 1 to (pNumPoints - pClosed) # last point will equal first if closed is true
- begin
- while (PtInRect(pointList[x],pVoidRect))
- begin
- thePointh := pointList[x][1];
- thePointv := pointList[x][2];
- if (global gDebugFlag)
- Println "{thePointh},{thePointv} is in the void rect - get another point";
- thePoint := GetRandomPointsRelativeToWindow(pInset, boundingRect);
- if (thePoint) pointList := replace(thePoint, x, pointList );
- else LogStr("GetRandomPointsRelativeToWindow() hosed");
- end;
- end;
- end;
-
- return( pointList );
- end; # MakePointList()
-
-
- #########################################################################
- # SetTool(pTool,pSelectTool, pObjectNumber)
- #========================================================================
- # Author: KTA
- # Description: This task takes a ToolStruct as a parameter. If the ToolStruct
- # evaluates to 'Random' a ToolStruct will be generated randomly.
- # If the pSelectTool evaluates to true the tool will also be selected.
- # Otherwise, the generated toolStruct will be returned without
- # selecting the tool.
- # Parameters: pTool - 0 - nothing done return 0
- # - Valid ToolStruct
- # - 'Random' - generates a random ToolStruct
- # pSelectTool - Boolean flag which indicates whether or not to
- # select the tool.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: 0 - nothing done 0 passed in.
- # Valid toolStruct
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SetTool(pTool := 'Random', pSelectTool := 1, pObjectNumber := 0)
- begin
- if (global gDebugFlag)
- begin
- Println "++++++++ SetTool() has just been called++++++++ ";
- Println "This is the toolStruct - ",pTool;
- end;
- global gToolList;
- if(pTool)
- begin
- if(pTool = 'Random')
- begin
- toolNum := Random(1,card(gToolList));
- pTool := gToolList[toolNum];
- #theObject := InsertElemStruct(pTool, theObject); # Insert the tool description
- if (global gDebugFlag)
- println " pTool after generating a random one in SetTool() - ", pTool;
- end;
- if (pSelectTool)
- begin
- PalettePicker(pTool,pObjectNumber);
- # This is where we put a hook for Dragging tools after selecting
- end;
- end;
- return(pTool);
- end;
-
- #########################################################################
- # GenerateObject(pTheObject)
- #========================================================================
- # Author: KTA
- # Description: This task generates valid elements for any element that evaluates
- # to 'Random'.
- # Parameters: pTheObject - A complete Object Struct. The default is to
- # generate all elements of the returned object
- # randomly. Passing in partially completed object
- # struct will replace the elements which evaluate
- # to 'Random' with valid data.
- # Returns: pTheObject - a complete objectStruct no elements will evaluate
- # to 'Random'
- # Examples: GenerateObject({global PointerTool,'Random',0,'Random','Random'})
- # Assumptions: All the necessary Draw Structs have been defined correctly.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK GenerateObject(pTheObject := {'Random','Random','Random','Random','Random'})
- begin
- if (global gDebugFlag)
- Println "----- GenerateObject() - Draw.lib --------";
-
- theTool := GetElemStruct(pTheObject);
- if (theTool = 'Random')
- theTool := SetTool(theTool, 0);
- pTheObject := InsertElemStruct(theTool,pTheObject);
-
- thePointList := GetPointList(pTheObject);
- if (thePointList = 'Random')
- thePointList := SetPointList(pTheObject);
- pTheObject := InsertPointList(thePointList, pTheObject);
-
- thePattern := GetPattern(pTheObject);
- if (thePattern = 'Random')
- thePattern := SetPattern(thePattern, 0);
- pTheObject := InsertPattern(thePattern,pTheObject);
-
- theLine := GetLine(pTheObject);
- if (theline = 'Random')
- theLine := SetLine(theLine, 0);
- pTheObject := InsertLine(theLine,pTheObject);
-
- theColor := GetColor(pTheObject);
- if (theColor = 'Random')
- theColor := SetColor(theColor, 0);
- pTheObject := InsertColor(theColor,pTheObject);
-
- Return(pTheObject);
- end; # GenerateObject()
-
- #########################################################################
- # SetPointList(pTheObject, pSpecifier)
- #========================================================================
- # Author: KTA
- # Description: Determines the number of points required for a given tool type.
- # Then calls MakePointList() to generate pointlist for different
- # tool types.
- # kClick tools - require a single point.
- # kDrag tools - require a two points.
- # All multipoint tools - access the global gNumPoints to
- # determine the number of points.
- # Parameters: pTheObject - a complete objectStruct with atleast a valid
- # ToolStruct.
- # pSpecifier - Specifier of the window in which to generate
- # points in.
- # Returns: thePointList - a list of point within <pSpecifier>
- # Examples: SetPointList(TheObjectStruct, 0);
- # Assumptions: All the necessary Draw Structs have been defined correctly.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SetPointList(pTheObject, pSpecifier := 0)
- begin
- global gNumPoints;
- if (global gDebugFlag)
- Println "++++++++ SetPointList() has just been called++++++++ ";
- theTool := GetElemStruct(pTheObject);
- thePointList := GetPointList(pTheObject);
- if(theTool)
- begin
- if (thePointList)
- begin
- if(thePointList = 'Random')
- begin
- elemType := GetElemType(theTool);
- if(elemType)
- begin
- # Create a point list and insert into the object structure
- # The number of points depends on the tool
- elemType := GetElemType(theTool);
- if (elemType <= 3) numPoints := elemType; # Click - pointlist will be 1/drag - pointlist will be 2
- else if(elemType = 7) numPoints := 1; # KDragOff tools only needs 1 point.
- else numPoints := gNumPoints;
-
- thePointList := MakePointList(,pSpecifier,numPoints);
- end;
- else
- thePointList := 0;
- end;
- end;
- end;
- else
- println "Sorry, can't generate a pointlist unless a tool has been defined";
-
- return(thePointList);
- end; # SetPointList()
-
- #########################################################################
- # Draw(pTheTool, pThePointList, pThePattern, pTheLine, pTheColor, pSpecifier )
- #========================================================================
- # Author: KTA
- # Description: This task provides a means for defining any of the elements
- # within an ObjectStruct and allowing the libraries to generate
- # any element that evaluates to 'Random' (default for all elements)
- # Parameters: 1 parameter for each of the elements of an objectStruct and
- # 1 additional parameter for the window pSpecifier.
- # pTheTool - ToolStruct
- # pThePointList - PointList (not user definable at this time)
- # pThePattern - PatternStruct
- # pTheLine - LineStruct
- # pTheColor - ColorStruct
- # pSpecifier - Window or rect to draw in
- # Returns: The actual ObjectStruct after generating 'Random' elements.
- # Examples: Draw(Global SelectTool, ‘Random’,0,0,{14,3, ‘Color’})
- # Assumptions: All the necessary Draw Structs have been defined correctly.
- #========================================================================
- # History:
- # ML 11/7/95 allow pThePointList to be user defineable.
- # ML 11/27/95 add support for gradients, background colors, text colors, pet pats
- # ML 11/29/95 use RandomDrawObject to generate random object
- #########################################################################
- TASK Draw(pTheTool := 'Random', pThePointList := 'Random', pThePattern := 'Random',
- pTheLine := 'Random', pTheColor := 'Random', pSpecifier := 0,
- pGradient := 'Random', pBGColor := 'Random', pTextColor := 'Random',
- pPenPat := 'Random')
- begin
- theObject := RandomDrawObject();
-
- if not(pTheTool = 'Random')
- theObject := InsertElemStruct(pTheTool, theObject);
-
- if not(pThePointList = 'Random') # We want to generate all pointlists for now KTA 7/92
- theObject := InsertPointList(pThePointList, theObject);
-
- if not(pThePattern = 'Random')
- theObject := InsertPattern(pThePattern, theObject);
-
- if not(pTheLine = 'Random')
- theObject := InsertLine(pTheLine, theObject);
-
- if not(pTheColor = 'Random')
- theObject := InsertColor(pTheColor, theObject);
-
- if not(pGradient = 'Random')
- theObject := InsertGradient(pGradient, theObject);
-
- if not(pBGColor = 'Random')
- theObject := InsertBackgroundColor(pBGColor, theObject);
-
- if not(pTextColor = 'Random')
- theObject := InsertTextColor(pTextColor, theObject);
-
- if not(pPenPat = 'Random')
- theObject := InsertPenPattern(pPenPat, theObject);
-
- theObject := DrawObject(theObject, pSpecifier);
- return(theObject);
- end;
-
- #########################################################################
- # SetColor(pTheColor, pSelectColor, pObjectNumber)
- #========================================================================
- # Author: KTA
- # Description: This is used when selecting colors from a palette.This task
- # takes a ColorStruct as a parameter. If the ColorStruct evaluates
- # to 'Random' a ColorStruct will be generated randomly.
- # If the pSelectColor evaluates to true the color will also be selected.
- # Otherwise, the generated ColorStruct will be returned without
- # selecting the color.
- # Parameters: pTheColor - 0 - nothing done return 0
- # - Valid ColorStruct
- # - 'Random' - generates a random ColorStruct
- # pSelectColor - Boolean flag which indicates whether or not to
- # select the Color.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: colStruct - A valid ColorStruct
- # Examples: SetColor('Random', 1, 14);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- # ML 11/09/95 Call SetPaletteItem
- #########################################################################
- TASK SetColor(pTheColor := 'Random', pSelectColor := 1, pObjectNumber := 0)
- begin
- return SetPaletteItem(pTheColor, pSelectColor, "Color", global kColorPaletteNum,
- pObjectNumber);
- end; # SetColor()
-
-
- #########################################################################
- # SetLine(pTheLine, pSelectLine, pObjectNumber)
- #========================================================================
- # Author: KTA
- # Description: This is used when selecting line weights from a palette.
- # This task takes a LineStruct as a parameter. If the LineStruct
- # evaluates to 'Random' a LineStruct will be generated randomly.
- # If the pSelectLine evaluates to true the line will also be selected.
- # Otherwise, the generated LineStruct will be returned without
- # selecting the line weight.
- # Parameters: pTheLine - 0 - nothing done return 0
- # - Valid LineStruct
- # - 'Random' - generates a random LineStruct
- # pSelectLine - Boolean flag which indicates whether or not to
- # select the line.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: LineStruct - A valid LineStruct
- # Examples: SetLine('Random', 1, 14);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- # ML 11/09/95 Call SetPaletteItem
- #########################################################################
- TASK SetLine(pTheLine := 'Random', pSelectLine := 1, pObjectNumber := 0)
- begin
- return SetPaletteItem(pTheLine, pSelectLine, "Line", global kLinePaletteNum,
- pObjectNumber);
- end; # SetLine()
-
- #########################################################################
- # SetLineMenuItems(pTheLine, pSelectLine, pObjectNumber)
- #========================================================================
- # Author: KTA
- # Description: This is used when selecting line weights from menuItems.
- # This task takes a LineStruct as a parameter. If the LineStruct
- # evaluates to 'Random' a LineStruct will be generated randomly.
- # If the ppSelectLine evaluates to true the tool will also be selected.
- # Otherwise, the generated LineStruct will be returned without
- # selecting the line weight. This task depends upon a global
- # gLineWeights to be defined as the menuItem titles of the menuitems
- # which are used to set line wieghts.
- # Parameters: pTheLine - 0 - nothing done return 0
- # - Valid LineStruct
- # - 'Random' - generates a random LineStruct
- # pSelectLine - Boolean flag which indicates whether or not to
- # select the line.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: LineStruct - A valid LineStruct
- # Examples: SetLine('Random', 1, 14);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- # KTA 8/24/93 TCS stack parity check
- #########################################################################
- TASK SetLineMenuItems(pTheLine := {}, pSelectLine := 1, pObjectNumber := 0)
- begin
- failStr := '';
- if (global gDebugFlag)
- println "++++++++ SetLine() has just been called++++++++ ";
- global gLineWeights;
- if(pTheLine)
- begin
- # If a weight is not passed then calculate a random one
- if(pTheLine = 'Random') # Random Line wieght
- begin
- whichWeight := random(1, Card(gLineWeights)); # Calculate which random weight to use
- TheLineWeight := gLineWeights[whichWeight]; # Set variable to actual weight
- pTheLine := { TheLineWeight, "Menu Item", "Line"};
- #theObject := InsertLine(lineStruct, theObject);
- end;
- else
- TheLineWeight := pTheLine[1];
-
-
- if(TheLineWeight) and (pSelectLine)
- begin
- TCSStart({ 1, global kTCSetDraw },"SetLineMenuItems"); # Start TCS
- returnVal := SelectMenuItem(TheLineWeight); # Select it
- if (returnVal)
- returnVal := 1;
- else
- begin
- failStr := "Failed to select menu item for line weight";
- LogStr(failStr);
- end;
- TCSEnd({ 1, global kTCSetDraw },returnVal,failStr,pObjectNumber,TheLineWeight);
- end;
- end;
- else
- LogStr("Null object passed to SetLine");
- return(pTheLine);
- end; # SetLineMenuItems()
-
- #########################################################################
- # SetPattern(pThePattern, pSelectPattern, pObjectNumber)
- #========================================================================
- # Author: KTA
- # Description: This is used when selecting patterns from a palette.
- # This task takes a PatternStruct as a parameter. If the PatternStruct
- # evaluates to 'Random' a PatternStruct will be generated randomly.
- # If the pSelectPattern evaluates to true the pattern will also be selected.
- # Otherwise, the generated PatternStruct will be returned without
- # selecting the pattern.
- # Parameters: pThePattern - 0 - nothing done return 0
- # - Valid PatternStruct
- # - 'Random' - generates a random PatternStruct
- # pSelectPattern - Boolean flag which indicates whether or not to
- # select the pattern.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: patStruct - A valid PatternStruct
- # Examples: SetPattern('Random', 1, 14);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- # ML 11/09/95 Call SetPaletteItem
- #########################################################################
- TASK SetPattern(pThePattern := 'Random', pSelectPattern := 1, pObjectNumber := 0)
- begin
- return SetPaletteItem(pThePattern, pSelectPattern, "Pattern", global kPatternPaletteNum,
- pObjectNumber);
- end; # SetPattern()
-
- #########################################################################
- # SetBackgroundColor(pBackgroundColor, pSelectItem, pObjectNumber)
- #========================================================================
- # Author: ML
- # Description: This is used when selecting Background Colors from a palette.
- # This task takes an element struct, item number, or "Random"
- # as a parameter. If 'Random', an element struct will be generated randomly.
- # If pSelectItem evaluates to true the element struct
- # will also be selected.
- # Parameters: pBackgroundColor - 0 - nothing done return 0
- # - Valid Item Num
- # - valid element struct
- # - 'Random' - generates a random element struct
- # pSelectItem - Boolean flag which indicates whether or not to
- # select the element.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: BackgroundColorStruct - A valid BackgroundColorStruct
- # Examples: SetBackgroundColor('Random', 1, 14);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- #########################################################################
- TASK SetBackgroundColor(pBackgroundColor := 'Random', pSelectItem := 1,
- pObjectNumber := 0)
- begin
- return SetPaletteItem(pBackgroundColor, pSelectItem, "Background Color",
- global kBackgroundColorPaletteNum, pObjectNumber);
- end; # SetBackgroundColor()
-
- #########################################################################
- # SetTextColor(pTextColor, pSelectItem, pObjectNumber)
- #========================================================================
- # Author: ML
- # Description: This is used when selecting Text Colors from a palette.
- # This task takes an element struct, item number, or "Random"
- # as a parameter. If 'Random', an element struct will be generated randomly.
- # If pSelectItem evaluates to true the element struct
- # will also be selected.
- # Parameters: pTextColor - 0 - nothing done return 0
- # - Valid Item Num
- # - valid element struct
- # - 'Random' - generates a random element struct
- # pSelectItem - Boolean flag which indicates whether or not to
- # select the element.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: TextColorStruct - A valid TextColorStruct
- # Examples: SetTextColor('Random', 1, 14);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- #########################################################################
- TASK SetTextColor(pTextColor := 'Random', pSelectItem := 1,
- pObjectNumber := 0)
- begin
- return SetPaletteItem(pTextColor, pSelectItem, "Text Color",
- global kTextColorPaletteNum, pObjectNumber);
- end; # SetTextColor()
-
- #########################################################################
- # SetPenPattern(pPenPattern, pSelectItem, pObjectNumber)
- #========================================================================
- # Author: ML
- # Description: This is used when selecting pen patterns from a palette.
- # This task takes an element struct, item number, or "Random"
- # as a parameter. If 'Random', an element struct will be generated randomly.
- # If pSelectItem evaluates to true the element struct
- # will also be selected.
- # Parameters: pPenPattern - 0 - nothing done return 0
- # - Valid Item Num
- # - valid element struct
- # - 'Random' - generates a random element struct
- # pSelectItem - Boolean flag which indicates whether or not to
- # select the element.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: PenPatternStruct - A valid PenPatternStruct
- # Examples: SetPenPattern('Random', 1, 14);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- #########################################################################
- TASK SetPenPattern(pPenPattern := 'Random', pSelectItem := 1,
- pObjectNumber := 0)
- begin
- return SetPaletteItem(pPenPattern, pSelectItem, "Pen Pattern",
- global kPenPatternPaletteNum, pObjectNumber);
- end; # SetPenPattern()
-
- #########################################################################
- # SetGradient(pGradient, pSelectItem, pObjectNumber)
- #========================================================================
- # Author: ML
- # Description: This is used when selecting gradients from a palette.
- # This task takes an element struct, item number, or "Random"
- # as a parameter. If 'Random', an element struct will be generated randomly.
- # If pSelectItem evaluates to true the element struct
- # will also be selected.
- # Parameters: pGradient - 0 - nothing done return 0
- # - Valid Item Num
- # - valid element struct
- # - 'Random' - generates a random element struct
- # pSelectItem - Boolean flag which indicates whether or not to
- # select the element.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: GradientStruct - A valid GradientStruct
- # Examples: SetGradient('Random', 1, 14);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- #########################################################################
- TASK SetGradient(pGradient := 'Random', pSelectItem := 1,
- pObjectNumber := 0)
- begin
- return SetPaletteItem(pGradient, pSelectItem, "Gradients",
- global kGradientPaletteNum, pObjectNumber);
- end; # SetGradient()
-
- #########################################################################
- # SetPaletteItem(pThePattern, pSelectPattern, pObjectNumber)
- #========================================================================
- # Author: ML
- # Description: This is used when selecting an item from a palette.
- # This task takes a palette item number as a parameter. If the palette item number
- # evaluates to 'Random' a palette item struct will be generated randomly.
- # If the pSelectPattern evaluates to true the palette item will also be selected.
- # Otherwise, the generated palette item struct will be returned without
- # selecting the palette item.
- # Parameters: pPaletteItem - 0 - nothing done return 0
- # - Valid Palette Item Num
- # - valid Palette item struct
- # - 'Random' - generates a random palette item struct
- # pSelectItem - Boolean flag which indicates whether or not to
- # select the palette item.
- # pPaletteName - string describing the name of the palette
- # pPaletteNum - the palette's position within the global gPaletteList
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: ItemStruct - A valid palette item struct
- # Examples: SetPaletteItem({ 8,3,"pattern" },0, "pattern", global kPatternPaletteNum);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- #########################################################################
- TASK SetPaletteItem(pPaletteItem := 'Random', pSelectItem := 1, pPaletteName:= "",
- pPaletteNum:= 0, pObjectNumber := 0)
- begin
- if (global gDebugFlag)
- begin
- Println "++++++++ SetPaletteItem() has just been called for the {pPaletteName} palette +++++++++";
- Println "This is the palette item struct - ",pPaletteItem;
- end;
- global gPaletteList;
- if (gPaletteList) and (pPaletteNum)
- begin
- if (pPaletteItem)
- begin
- if(pPaletteItem = 'Random') # Random item
- begin
- thePalette := gPaletteList[pPaletteNum];
- pPaletteItem := GetRandomElement(thePalette);
- end;
- if (TypeOf(pPaletteItem) = 'integer')
- ItemStruct := { pPaletteItem, pPaletteNum, "{pPaletteName}"}; # create a struct to send to the palette picker
- else
- ItemStruct := pPaletteItem;
-
- if(ItemStruct) and (pSelectItem)
- PalettePicker(ItemStruct, pObjectNumber);
- end;
- else
- ItemStruct := 0;
- end;
- else
- begin
- ItemStruct := 0;
- if (global gDebugFlag)
- Println "Either the gPaletteList or the {pPaletteName} palette is not defined";
- end;
- return(ItemStruct);
- end; # SetPaletteItem()
-
- #########################################################################
- # CheckSetup()
- #========================================================================
- # Author: KTA
- # Description: Reports the current state of various draw related
- # globals and global structures. Call this task after a script
- # has defined all of its draw related globals. This routine will
- # print the current setting. A review of the output could help
- # to reveal any problems with the initial setup.
- # Parameters: none
- # Returns: nothing
- # Examples: CheckSetup();
- #========================================================================
- # History:
- # KTA 7/18/94 changed the reporting so the current palette is 4 elements it is
- # global coordinates and if 5 it is relative to the specified window
- #########################################################################
- TASK CheckSetup()
- begin
- global kPalDocWind, kPalWind, kPopUpPal;
-
- Println "The Bounding Rect is - ", global gBoundingRect; # Window inset
- Println "The Void Rect is - ", global gVoidRect; # Rect not to draw in - coordinates should be RelativeToWindow
- Println "The Number of point that all multipoint object will be drawn is - '{global gNumPoints}'";
- Println "The Global TextStr is - '{global gTextStr}'";
- For i := 1 to Card(global gPaletteList)
- begin
- CurrentPalette := gPaletteList[i];
- Println;
- if (CurrentPalette[2] = kPopUpPal)
- begin
- PopPoint := {CurrentPalette[1][1],CurrentPalette[1][2]};
- Println "•• Palette number - '{i}' is a popup Palette with a poppoint at ",PopPoint;
- TLFirstElem := {CurrentPalette[1][3],CurrentPalette[1][4]};
- Println "•• The TopLeft of first elem is ",TLFirstElem;
- if (Card(CurrentPalette[1]) = 4)
- Println "•• The popPoint and TopLeft are absolute coordinates";
- else if (Card(CurrentPalette[1]) = 5)
- Println "•• The popPoint and TopLeft coordinates are relative to the specified window";
- Println "•• It is type - ",CurrentPalette[2], " which is a kPopUpPal ( pop up palette )";
- end;
- else if (CurrentPalette[2] = kPalWind)
- begin
- Println "•• Palette number - '{i}' has the specifier of - ",CurrentPalette[1][1];
- Println "•• It is type - ",CurrentPalette[2], " which is a kPalWind ( palette contained within its own window )";
- Println "•• The vertical distance between the top of the window and the top of the 1st tool is - ", CurrentPalette[1][2];
- end;
- else if (CurrentPalette[2] = kPalDocWind)
- Println "•• It is type - ",CurrentPalette[2], " which is a kPalDocWind ( contained within a documents window )";
-
- Println "•• The size of the Tool matrix is - ", CurrentPalette[3];
- Println "•• The Offset between tools is - ", CurrentPalette[4];
-
- Struct := { 1, i, "FirstItem"}; # create a struct to send to the palette picker
- PalettePicker(Struct);
- FinalTool := CurrentPalette[3][1] * CurrentPalette[3][2];
- Struct := { FinalTool, i, "LastItem"}; # create a struct to send to the palette picker
- PalettePicker(Struct);
- Println;
- end;
- global gToolList;
- end; # CheckSetup()
-
- #########################################################################
- # RandomDrawObject()
- #========================================================================
- # Author: ML
- # Description: Generate a draw object with 'random' for all items.
- # Parameters: none
- # Returns: a draw object with 'random' for all items
- # Examples: RandomDrawObject();
- #========================================================================
- # History:
- #########################################################################
- TASK RandomDrawObject()
- begin
- return ({'Random','Random','Random','Random','Random',
- 'Random','Random','Random','Random'});
- end;